<?php
/*
 * @Author: 哲学家乔布斯 <wuyangii@qq.com>
 * @Date: 2022-10-25 20:19:21
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-25 20:22:43
 * @Descripttion: 
 */


namespace app\common\model;

use think\Model;

class UserCoupon extends Base
{
    protected $insert = ['addtime'];
    protected $type = [
        1 => '无门槛', 2 => '满减', 3 => '指定商品',
    ];

    //---------------自动完成----------------------
    protected function setAddtimeAttr()
    {
        return time();
    }
    public function getAddtimeTextAttr($value, $data){
        return date('Y-m-d', $data['addtime']);
    }
    public function getEdntimeTextAttr($value, $data){
        return date('Y-m-d', $data['edntime']);
    }
    public function getUsetimeTextAttr($value, $data){
        return date('Y-m-d', $data['usetime']);
    }
   

    public function getImageTextAttr($value,$data){
        return $data['image'] ? cdnurl($data['image'],true) : "";
    }
    public function getTypeTextAttr($value,$data){
        return $this->type[$data['type']];
    }
    public function getTpyeTextAttr($value,$data){
        // if($data['tpye'] == 0){
        //     return "平台";
        // }
        // return "商家";
        if($data['bus_id'] == 0){
                return "平台";
            }
        return "经销商";
    }
    public function getBusTextAttr($value,$data){
        $data = (new \app\common\model\Bus())->where(['id' => $data['bus_id']])->value('user_name');
        if(!empty($data)){
            return $data;
        }
        return "平台";
    }
    public function getStateTextAttr($value,$data){
        if($data['edntime'] <= time()){
            return 2;
        }else{
            return $data['state'];
        }
    }

    public function getStateTexttAttr($value,$data){
        $arr = [0=>'未使用',1=>'使用'];
        if($data['edntime'] <= time()){
            return '过期';
        }else{
            return $arr[$data['state']];
        }
    }
    public function getUserUsernameAttr($value,$data){
        return (new \app\common\model\User())->where(['id' => $data['user_id']])->value('username');
    }
}
